package ${package};

<#list imports as imp>
import ${imp};
</#list>
import java.util.List;
import java.util.LinkedList;
import com.bingquan.base.msg.AbstractRequestBean;
import com.bingquan.base.msg.RequestMsg;
import com.bingquan.base.msg.ResponseMsg;
import com.tianlei.guaji.msg.MessageCode;
/**
*${desc}
<#if type=="REQ">${respDesc}*</#if>
*@auther ${author} 
*/
public class ${name} <#if type=="REQ"> extends AbstractRequestBean<#elseif type=="RESP">extends ResponseMsg</#if>{
<#list properties as pro>
	/**${pro.desc}*/
	public  <#if pro.ref =="list">List<<@TYPE>${pro.type}</@TYPE>><#else>${pro.type}</#if> ${pro.name};
</#list>
	/**空的构造方法*/
	public ${name}()
	{/**do nothing*/}

	<#if type=="REQ" ||type=="BEAN">
	public void readData(RequestMsg requestMsg)throws Exception{
	<#list properties as pro>
		<#if pro.isif!=true>
			<#if pro.ref =="bean"> 
		${pro.name}=new ${pro.type}();
		${pro.name}.readData(requestMsg);
			<#elseif pro.ref=="list">
		${pro.name}=new LinkedList<<@TYPE>${pro.type}</@TYPE>>();
		int ${pro.name}Size=requestMsg.getShort();
		for(int i=0;i<${pro.name}Size;i++){
			<#if pro.type?ends_with("Bean")> 
			${pro.type} tempBean=new ${pro.type}();
			tempBean.readData(requestMsg);
			<#else>
			${pro.type} tempBean=requestMsg.get<@TYPE>${pro.type}</@TYPE>();
			</#if>
			${pro.name}.add(tempBean);
		}
			<#else>
		${pro.name}=requestMsg.get<@TYPE>${pro.type}</@TYPE>();
				<#list pro.ifs as ifc>
					if(${pro.name} ${ifc.flag} ${ifc.value}){
						<#list ifc.properties as p>
							<#if p.ref =="bean"> 
		${p.name}=new ${p.type}();
		${p.name}.readData(requestMsg);
							<#elseif p.ref=="list">
		${p.name}=new LinkedList<<@TYPE>${p.type}</@TYPE>>();
		int ${p.name}Size=requestMsg.getShort();
		for(int i=0;i<${p.name}Size;i++){
			<#if p.type?ends_with("Bean")> 
			${p.type} tempBean=new ${p.type}();
			tempBean.readData(requestMsg);
			<#else>
			${p.type} tempBean=requestMsg.get<@TYPE>${p.type}</@TYPE>();
			</#if>
			${p.name}.add(tempBean);
		}
							<#else>
		${pro.name}=requestMsg.get<@TYPE>${pro.type}</@TYPE>();
							</#if>
						</#list>
					}
				</#list>
			</#if>
			
		<#else>
			
		</#if>
	</#list>
	}
	</#if>
	<#if type=="RESP" ||type=="BEAN">
	public void writeData(ResponseMsg responseMsg)throws Exception{
	<#if type!="BEAN">
		setMsgCode(MessageCode.${conName});
	</#if>
	<#list properties as pro>
	<#if pro.isif!=true>
		<#if pro.ref =="bean"> 
		${pro.name}.writeData(requestMsg);
		<#elseif pro.ref=="list">
		responseMsg.setShort(${pro.name}.size());
		for (<@TYPE>${pro.type}</@TYPE> tempBean : ${pro.name}){
			<#if pro.type?ends_with("Bean")> 
			tempBean.writeData(responseMsg);
			<#else>
			responseMsg.set<@TYPE>${pro.type}</@TYPE>(tempBean);
			</#if>
		}
		<#else>
		responseMsg.set<@TYPE>${pro.type}</@TYPE>(${pro.name});
		<#list pro.ifs as ifc>
				if(${pro.name} ${ifc.flag} ${ifc.value}){
					<#list ifc.properties as p>
						<#if p.ref =="bean"> 
							${p.name}.writeData(requestMsg);
						<#elseif p.ref=="list">
							responseMsg.setShort(${p.name}.size());
							for(<@TYPE>${p.type}</@TYPE> tempBean : ${p.name}){
								<#if p.type?ends_with("Bean")> 
								tempBean.writeData(requestMsg);
								<#else>
								responseMsg.set<@TYPE>${p.type}</@TYPE>(tempBean);
								</#if>
							}
						<#else>
							responseMsg.set<@TYPE>${p.type}</@TYPE>(${p.name});
						</#if>
					</#list>
				}
			</#list>
		</#if>
	</#if>
	</#list>
	}
	</#if>
	<#if type!="BEAN">
	@Override
	public  short getMsgCode()
	{
		return MessageCode.${conName};
	}
	</#if>
	
	<#if type=="REQ">
	@Override
	public boolean validate(){
		<#list properties as pro>
			<#if pro.type !="String" && !pro.type?ends_with("Bean")>
		if(${pro.name}<<@TYPE>${pro.type}</@TYPE>.valueOf("0")){
			return false;
		}
			</#if>
		</#list>
		return true;
	}
	
	</#if>
	
	public String toString(){
		return "${name}["+<#list properties as pro>", ${pro.name}:"+${pro.name}+</#list>"]";

	}
}